package com.ruoyi.hr.controller.hr.welfare.welfarecalculation;

import com.ruoyi.common.core.controller.BaseController;

import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.welfare.welfarecalculation.WelfareCalculationHistoryService;
import com.ruoyi.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 月福利历史
 *
 * @author zeo
 * @date 2020-1-14
 */
@Controller
@RequestMapping("/welfare/calculationHistory")
public class WelfareCalculationHistoryController extends BaseController {

    @Autowired
    WelfareCalculationHistoryService welfareCalculationHistoryService;

    @Autowired
    AuthorityService authorityService;

    private String prefix = "hr/welfare/welfarecalculation/welfarecalculationhistory";

    @GetMapping()
    public String calculation() {
        return prefix + "/welfarecalCulationHistory";
    }

    /**
     * 获取薪资套历史列表
     *
     * @return 薪资套列表集合
     */
    @PostMapping("/getBenefitProcess")
    @ResponseBody
    public List<Map<String, Object>> getBenefitProcess() {
        List<Map<String, Object>> maps = welfareCalculationHistoryService.getBenefitProcess();
        return maps;
    }

    /**
     * 获取人员福利历史数据
     *
     * @param jsid
     * @return
     */
    @PostMapping("/findEmpWelfareHistoryData")
    @ResponseBody
    public TableDataInfo findEmpWelfareHistoryData(String jsid, @RequestParam Map map) {
        SysUser user = ShiroUtils.getSysUser();
        List<Authority> authorityList = authorityService.getAuthorityUser(user.getUserId().toString());
        int isAdmin = 0;
        if (authorityList.size() == 1) {
            if (authorityList.get(0).getIsAdmin() != null) {
                isAdmin = 1;
            }
        }
        startPage();
        List<Map<String, Object>> list = welfareCalculationHistoryService.findEmpWelfareHistoryData(jsid,map,authorityList,isAdmin);
        return getDataTable(list);
    }
}
